using System;
using System.Collections.Generic;
using System.Text;

using System.Collections;
using System.Data;

using PHSRAG.Insight21.BusinessObjects;
using PHSRAG.Utility;
using PHSRAG.Insight21.Policy;

namespace PHSRAG.Insight21.Admin
{
	public class ResearchContacts : BusinessObject
	{
		public ResearchContacts(ICachePolicy cachePolicy)
			: base(cachePolicy)
		{
		}

		public override void Load(string connectionString, params object[] args)
		{
			try
			{
                
                    DataContainer = Utility.DataAccess.GetDataSet(connectionString, "GetResearchFinanceInfo");
                                
			}
			catch (Exception e)
			{
				Utility.ExceptionReport.WriteToEventLog("Failed to load ResearchFinanceInfo", e, true, Utility.ExceptionReport.ReportType.Error);
				throw;
			}
		}

        public void LoadAdminContacts(string connectionString, int instId, string strChiefCode, string strLastName, string firstName)
        {
            try
            {
                DataContainer = Utility.DataAccess.GetDataSet(connectionString, "GetAdminContactInfo",
                                             Utility.DataAccess.BuildSqlParameterArray("@instId", SqlDbType.Int,instId ,
                                                                                        "@chiefCode", SqlDbType.VarChar,strChiefCode ,
                                                                                        "@lastName", SqlDbType.VarChar,strLastName ,
                                                                                         "@firstName", SqlDbType.VarChar, firstName));

            }
            catch (Exception e)
            {

                Utility.ExceptionReport.WriteToEventLog("Failed to load ResearchFinanceInfo", e, true, Utility.ExceptionReport.ReportType.Error);
                throw;
            }
        
        
        }

		public static DataTable GetInstitutions(string connectionString)
		{
			try
			{
				return DataAccess.GetDataTable(connectionString, "GetAllInstitutions");
			}
			catch (Exception ex)
			{
				throw new Exception("Failed while retrieving Institutions", ex);
			}
		}

		public static DataTable GetChiefCodes(string connectionString, int institutionId)
		{
			try
			{
				return DataAccess.GetDataTable(connectionString, "GetChiefCodes", 
					Utility.DataAccess.BuildSqlParameterArray(
					"@institutionId", SqlDbType.Int, institutionId));
			}
			catch (Exception ex)
			{
				throw new Exception(string.Format("Failed while retrieving Chief codes for Insitution with id - {0}", institutionId), ex);
			}
		}

       
        public static DataTable GetRoles(string connectionString)
        {
            try
            {
                return DataAccess.GetDataTable(connectionString, "GetRoles");
                    
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Failed while retrieving Roles"), ex);
            }
        }
       
        public static DataTable GetSponsorTypes(string connectionString, int roleId)
        {
            try
            {
                return DataAccess.GetDataTable(connectionString, "GetsponsorByRolId",
                    Utility.DataAccess.BuildSqlParameterArray(
                    "@roleId", SqlDbType.Int, roleId));
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Failed while retrieving sponsor for Roles with id - {0}", roleId), ex);
            }
        }

	}
}
